﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MySql.Data.MySqlClient;
using IPTV.DBUtility;
using IPTV.module;
using System.Data;

/// <summary>
/// Summary description for PlateDao
/// </summary>
namespace IPTV.dao
{
    public class ZsdDao
    {
        public ZsdDao()
        {
            
        }

        public List<me_tgsg_category_video> getZsdById(string id)
        {

            string sql = " select cv.videoname,cv.videoid,cve.small_url,t.name,cve.video_length,cve.remark , cv.id  "
                    + " from me_tgsg_category_video cv,cms_video_ext cve,teacher t "
                    + " where cv.videoid =cve.video_id and cve.teacher_id = t.ID  and deleteflag = 0 and cv.categoryid = @id "
                    + " ORDER BY cv.displayorder asc,cv.refreshtime desc ";

            MySqlParameter[] parms = new MySqlParameter[] 
                { 
                    new MySqlParameter( "@id" , MySqlDbType.VarChar, 36 )
                };

            parms[0].Value = id;
            List<me_tgsg_category_video> zsdList = new List<me_tgsg_category_video>();
            try
            {
                MySqlDataReader reader = MySQLHelper.ExecuteReader(MySQLHelper.CONNECTION_STRING, sql, parms);

                while (reader.Read())
                {
                    me_tgsg_category_video zsd = new me_tgsg_category_video();
                    zsd.Videoname = reader[0].ToString();
                    zsd.Videoid = reader[1].ToString();
                    zsd.SmallUrl = reader[2].ToString();
                    zsd.TeacherName = reader[3].ToString();
                    zsd.VideoLength = reader[4].ToString();
                    zsd.Remark = reader[5].ToString();
                    zsd.Id = reader[6].ToString();
                    zsd.Categoryid = id;
                    zsdList.Add(zsd);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            return zsdList;

        }

       public string  getTagById(string tagIds)
        {
            String[] tempIds = tagIds.Split(';');
            string tempPara = "";
            List<String> paraList = new List<string>();
            for (int i = 0; i < tempIds.Length; i++ )
            {
                string tmp = tempIds[i];
                if (!tmp.Equals(""))
                {
                    String[] tmp2 = tmp.Split('$');

                    for (int j = 0; j < tmp2.Length; j++)
                    {
                        if (!"".Equals(tmp2[j].Trim()))
                        {
                            paraList.Add(tmp2[j]);

                        }
                    }
                }

            }

            for(int i =0;i<paraList.Count ; i++)
            {
                tempPara += "'" + paraList[i] + "'";
                if(i!= paraList.Count  -1)
                {
                    tempPara+=",";
                }

            }

            DictionaryDao dictionaryDao = new DictionaryDao();
           return dictionaryDao.findTags(tempPara);
        }
    
    }
}